﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace PECommon
{
    public class PECalcTool
    {
        /// <summary>
        /// 基于分线ID + StageID生成WorldID
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="stageID"></param>
        /// <returns></returns>
        public static ulong GetWorld(int prefix, int stageID)
        {
            return ((ulong)prefix << 32) + (ulong)stageID;
        }

        /// <summary>
        /// 生成MD5
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetMD5Hash(string input)
        {
            byte[] inputBytes = Encoding.UTF8.GetBytes(input);
            byte[] hashBytes = MD5.HashData(inputBytes);
            StringBuilder stringBuilder = new();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                stringBuilder.Append(hashBytes[i].ToString("x2"));
            }
            return stringBuilder.ToString();
        }
    }
}

